<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>干扰频谱管理</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/demo/demo.css">
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-easyui-1.3.5/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/Highcharts-5.0.14/code/highcharts.js"></script>
	<script src="${pageContext.request.contextPath}/static/Highcharts-5.0.14/code/modules/exporting.js"></script>
	<script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script>
	<!-- 中文包要放在exporting.js下面，否则无效 -->
</head>
<body>
	<%String FrontId = request.getParameter("FrontId");
	String TimeBegin = request.getParameter("TimeBegin");
	String TimeEnd = request.getParameter("TimeEnd");
	String Direction = request.getParameter("Direction");
	String InfChannel= request.getParameter("InfChannel");
	String InfType=request.getParameter("InfType");
	String InfIntensity=request.getParameter("InfIntensity");
	System.out.println("haha"+InfIntensity);
	String TCH=request.getParameter("TCH");
	String BCCH=request.getParameter("BCCH");
	String LAC=request.getParameter("LAC");
	String CI=request.getParameter("CI");
	String LAC1=request.getParameter("LAC1");
	String CI1=request.getParameter("CI1");
	String BCCH1=request.getParameter("BCCH1");
	String TRXs=request.getParameter("TRXs");
	String MCC=request.getParameter("MCC");
	String MNC=request.getParameter("MNC");
	String RXLEV=request.getParameter("RXLEV");%>
    <div id="tb">
 	<!-- <div>
        <a href="javascript:checkreturn()" class="easyui-linkbutton" iconCls="icon-back" plain="true">返回</a>
 	</div> -->
 	<div font-size:18px>
 	干扰信息：<br/>
 	基站名：<%=FrontId %>&nbsp;&nbsp;&nbsp;&nbsp;开始时间：<%=TimeBegin %>&nbsp;&nbsp;&nbsp;&nbsp;结束时间：<%=TimeEnd %>&nbsp;&nbsp;&nbsp;&nbsp;方向：<%=Direction %>&nbsp;&nbsp;&nbsp;&nbsp;干扰强度：<%=InfIntensity %>&nbsp;&nbsp;&nbsp;&nbsp;干扰频道：<%=InfChannel %>&nbsp;&nbsp;&nbsp;&nbsp;干扰类型：<%=InfType %><br/>
 	基站信息：<br/>
 	LAC：<%=LAC %>&nbsp;&nbsp;&nbsp;&nbsp;CI：<%=CI %>&nbsp;&nbsp;&nbsp;&nbsp;BCCH：<%=BCCH %>&nbsp;&nbsp;&nbsp;&nbsp;TCH：<%=TCH %><br/>
 	扫频信息：<br/>
 	LAC：<%=LAC1 %>&nbsp;&nbsp;&nbsp;&nbsp;CI：<%=CI1 %>&nbsp;&nbsp;&nbsp;&nbsp;BCCH：<%=BCCH1 %>&nbsp;&nbsp;&nbsp;&nbsp;TRXs：<%=TRXs %><br/>
 	MCC：<%=MCC %>&nbsp;&nbsp;&nbsp;&nbsp;MNC：<%=MNC %>&nbsp;&nbsp;&nbsp;&nbsp;RXLEV：<%=RXLEV %><br/>
 	
 	</div>
 	<br/>
 	<div>
 	<br>
        <input name="operation" type="button" id="operation" value="暂停" onclick="dealwith(this.value);"/>
        <input name="replay" type="button" id="replay" value="重新播放" onclick="replay();"/>
        &nbsp;&nbsp;当前时刻：<input type="text" id="currenttime" name="currenttime" class="easyui-validatebox" values="" style="text-align:center;width: 200px" />
 	
 		<textarea id="bs_info" style="float:right;width:calc(25%);height:90px;border: solid 0px;outline:none;" readonly></textarea>
 	</div>
 	<br/><br/>
    </div>
    <br><br><br>
	<div id="container" style="float:left;width:calc(50%);height:500px"></div>
	<div id="container2" style="float:left;width:calc(50%);height:500px"></div>
	<script>
	
	/* 采用每读一分钟就显示1分钟的数据的方法来对频谱进行显示 */
	var flag=true;
    var time=1000;
    var status=false;
    var isreplay=false;
    var status2=false;
    var isreplay2=false;
    var frontId="<%=FrontId %>";
    var beginTime="<%=TimeBegin %>";
    var endTime="<%=TimeEnd %>";
    
    var direction = "<%=Direction %>";
    
    var length=beginTime.length;
    var length1=endTime.length;
    var begintimelong=parseInt(new Date(beginTime.substring(0,length-4).replace(new RegExp("-","gm"),"/")).getTime());
    var tmp=parseInt(beginTime.substring(length-3,length));
    begintimelong=begintimelong+tmp;
    var middletime;
    var tmptime; //用于保存初始时间用来重新播放
    var endtimelong=parseInt(new Date(endTime.substring(0,length1-4).replace(new RegExp("-","gm"),"/")).getTime());
    var tmp1=parseInt(endTime.substring(length-3,length));
    endtimelong=endtimelong+tmp1;
    middletime=begintimelong+60000;
    tmptime=begintimelong;
	if(middletime>endtimelong){
		middletime=endtimelong;
	}
    var FSpectrum=new Array();  //上行频谱
    var FSpectrum1=new Array();  //下行频谱
    var currenttime=new Array();  //时间
    var timer;
    var timer2;
    var bsmodelbusy=new Array();
    var bsmodelleisure=new Array();
    var bsmodelbusy2=new Array();
    var bsmodelleisure2=new Array();
    
    console.log(direction);
    setupBSInfo(frontId);
    
    
	Highcharts.setOptions({
    global: {
        useUTC: false
    }
});
	
	/* function checkreturn(){
		clearInterval(timer);
    	clearInterval(timer2);
		window.location.href="InterferenceQuery.jsp";
	} */
	
	function formatData(val,row){
		return row.data.Data;
	};

	var frequencySpectrum_CURRENT_QUANTITY;
	
	var toArray = function(s){  
	    try{  
	        return Array.prototype.slice.call(s);  
	    } catch(e){  
	            var arr = [];  
	            for(var i = 0,len = s.length; i < len; i++){  
	                //arr.push(s[i]);  
	                 arr[i] = s[i];     //据说这样比push快
	            }  
	             return arr;  
	    } 
	}
    function dealwith(obj){
    	if( obj == '暂停' ){
    		  status=true;
    		  status2=true;
    	      document.getElementById('operation').value = '播放';
    	}
    	else{
    		  status=false;
    		  status2=false;
    	      document.getElementById('operation').value = '暂停';
    	}
    	
    }
    
    function replay(){
    	clearInterval(timer);
    	clearInterval(timer2);
    	middletime=tmptime;
    	flag=true;
        time=1000;
        status=false;
        isreplay=false;
        status2=false;
        isreplay2=false;
        chartplay();
	}

	Highcharts.setOptions({
	    global: {
	        useUTC: false
	    }
	});
		
	Highcharts.setOptions({
	    // 所有语言文字相关配置都设置在 lang 里
	    lang: {
	        resetZoom: '重置',
	        resetZoomTitle: '重置缩放比例'
	    }
	});
	
	var chart1=new Highcharts.chart({
	    	credits:{
			     enabled:false // 禁用版权信息
			},
	        chart: {
	        	renderTo: 'container',   //通过 chart.renderTo 来指定highchart名称
	            type: 'spline',
	            	zoomType: 'xy',
	    	        animation: Highcharts.svg, // don't animate in old IE
	    	        marginRight: 10,
	    	        events: {
	    	            load: function () {
	    	                // set up the updating of the chart each second
	    	                var series_bsmodelbusy = this.series[0]; 
	    	                var series_bsmodelleisure = this.series[1];
	    	                var chart = this;
	    	                var tmp=998;
	    	                var sum=0;
	    	                var fs=new Array();
	    	                for(var j=998;j<=1020;j=j+1/21){
	    	                	if(sum==21){
	    	                		this.xAxis[0].categories.push(tmp+1);
	    	                		tmp=tmp+1;
	    	                		sum=0;
	    	                	}
	    	                	else
	    	                    	this.xAxis[0].categories.push(j);
	    	                	sum=sum+1;
	    	                } 
	    	            	$.post("${pageContext.request.contextPath}/interferencequery/bsmodellist.do",{frontId:frontId,direction:"0"},function(result){
	    	            		var r=result.rows;
	    	            		for(var i=0;i<463;i++)
	    	            		{
	    	            			if(i<11||i>451)
	    	            			{
	    	            				bsmodelbusy[i]=null;
	    	            				bsmodelleisure[i]=null;
	    	            				
	    	            			}
	    	            			else{
	    	            				bsmodelbusy[i]=parseFloat(r[i-11].busyFloor)
	    	            				bsmodelleisure[i]=parseFloat(r[i-11].leisureFloor)
	    	            		
	    	            			}
	    	            		}
	    	            		series_bsmodelbusy.setData(bsmodelbusy);
	    	            		series_bsmodelleisure.setData(bsmodelleisure);
		    	       			 if(!result.success){
		    	       				$.messager.alert("系统提示","获取参数失败！");
		    	       			 }
	    	       			},"json");
	    	            	
	    	               
	    	            } 
	    	        }
	        },
	        title: {
	            text: '频谱回放(上行)'
	        },
	        xAxis: {
	        	tickInterval: 21,
	        	allowDecimals:false,
	        	title: {
	                text: '频道号'
	            },
	               categories:[]
	        },
	        yAxis: {
	            title: {
	                text: '频谱值(dBm)'
	            },
	            labels: {
	                formatter: function () {
	                    return this.value + '';
	                }
	            },
	            tickInterval: 2,
	            tickPositions: [-120,-110,-100,-90,-80, -70, -60,-50,-40,-30,-20]
	        },
	        tooltip: {
	            crosshairs: true,
	            shared: true,
	            valueDecimals : 1
	        },
	        plotOptions: {
	            spline: {
	                marker: {
	                    radius: 4,
	                    lineWidth: 0.5
	                }
	            }
	        },
	        Color: ['#7cb5ec', '#434348', '#90ed7d'],
	        exporting: {
		        enabled: true
		    },
		    
	        series: [{
	            name: '忙时底噪',
	            marker: {
	            	 enabled: false
	            }, 
	            data: [],
	            color:'#000000',
	            lineWidth: 0.95,
	            visible: direction == '上行'
	        },{
	            name: '闲时底噪',
	            marker: {
	            	 enabled: false
	            }, 
	            data: [],
	            color:'#FF0000',
	            lineWidth: 0.95,
	            visible: direction == '上行'
	        },{
	            name: '频谱信号',
	            marker: {
	            	 enabled: false
	            }, 
	            data: [],
	            color:"#0000FF",
	            lineWidth: 1
	        }]
	    });
	
	var chart2=new Highcharts.chart({
	    	credits:{
			     enabled:false // 禁用版权信息
			},
	        chart: {
	        	renderTo: 'container2',   //通过 chart.renderTo 来指定highchart名称
	                type: 'spline',
	            	zoomType: 'xy',
	    	        animation: Highcharts.svg, // don't animate in old IE
	    	        marginRight: 10,
	    	        events: {
	    	            load: function () {
	    	            	var series_bsmodelbusy = this.series[0]; 
	    	                var series_bsmodelleisure = this.series[1];
	    	                // set up the updating of the chart each second
	    	                var chart = this;
	    	                var tmp=998;
	    	                var sum=0; 
	    	                var fs=new Array();
	    	                for(var j=998;j<=1020;j=j+1/21){
	    	                	if(sum==21){
	    	                		this.xAxis[0].categories.push(tmp+1);
	    	                		tmp=tmp+1;
	    	                		sum=0;
	    	                	}
	    	                	else
	    	                    	this.xAxis[0].categories.push(j);
	    	                	sum=sum+1;
	    	                } 
	    	            	$.post("${pageContext.request.contextPath}/interferencequery/bsmodellist.do",{frontId:frontId,direction:"1"},function(result){
	    	            		var r=result.rows;
	    	            		for(var i=0;i<463;i++)
	    	            		{
	    	            			if(i<11||i>451)
	    	            			{
	    	            				bsmodelbusy2[i]=null;
	    	            				bsmodelleisure2[i]=null;
	    	            				
	    	            			}
	    	            			else{
	    	            				bsmodelbusy2[i]=parseFloat(r[i-11].busyFloor)
	    	            				bsmodelleisure2[i]=parseFloat(r[i-11].leisureFloor)
	    	            		
	    	            			}
	    	            		}
	    	            		series_bsmodelbusy.setData(bsmodelbusy2);
	    	            		series_bsmodelleisure.setData(bsmodelleisure2);
		    	       			 if(!result.success){
		    	       				$.messager.alert("系统提示","获取参数失败！");
		    	       			 }
	    	       			},"json");
	    	            } 
	    	        }
	        },
	        title: {
	            text: '频谱回放(下行)'
	        },
	        xAxis: {
	        	tickInterval: 21,
	        	allowDecimals:false,
	        	title: {
	                text: '频道号'
	            },
	               categories:[]
	        },
	        yAxis: {
	        	pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>',
	            title: {
	                text: '频谱值(dBm)'
	            },
	            labels: {
	                formatter: function () {
	                    return this.value + '';
	                }
	            },
	            tickInterval: 2,
	            tickPositions: [-120,-110,-100,-90,-80, -70, -60,-50,-40,-30,-20]
	        },
	        tooltip: {
	            crosshairs: true,
	            shared: true,
	            valueDecimals : 1
	        },
	        plotOptions: {
	            spline: {
	                marker: {
	                    radius: 4,
	                    lineColor:['#7cb5ec', '#434348', '#90ed7d'],
	                    lineWidth: 0.5
	                }
	            }
	        },
	        exporting: {
		        enabled: true
		    },
	        series: [{
	            name: '忙时底噪',
	            marker: {
	            	 enabled: false
	            }, 
	            data: [],
	            color:'#000000',
	            lineWidth: 0.95,
	            visible: direction == '下行'
	            
	        },{
	            name: '闲时底噪',
	            marker: {
	            	 enabled: false
	            }, 
	            data: [],
	            color:'#FF0000',
	            lineWidth: 0.95,
	            visible: direction == '下行'
	        },{
	            name: '频谱信号',
	            marker: {
	            	 enabled: false
	            }, 
	            data: [],
	            color:"#0000FF",
	            lineWidth: 1
	        }]
	    });
     
	
	chartplay();
	
	/* 干扰频谱回放显示函数 */
	function chartplay(){
		var series_bsmodelbusy = chart1.series[0]; 
        var series_bsmodelleisure = chart1.series[1];
        var series_bsmodelbusy1 = chart2.series[0]; 
        var series_bsmodelleisure1 = chart2.series[1];
		var series_FSpectrum = chart1.series[2];  //上行
		var series_FSpectrum1 = chart2.series[2]; //下行
		var p1=0;
		$.post("${pageContext.request.contextPath}/interferencequery/fslist.do",{frontId:frontId,startTime:begintimelong,endTime:middletime,isAdjust:"0",isfsreplay:"0"},
        		function(fsresult){
        		var fs=fsresult.rows1;
        		var fs1=fsresult.rows;
        		for(var i=0;i<fs.length;i++){
        			FSpectrum[i]=new Array();
        			FSpectrum1[i]=new Array();
        			currenttime[i]=fs[i].timeStamp;
        			FSpectrum[i]=fs[i].rawMessage.split(",");
        			FSpectrum1[i]=fs1[i].rawMessage.split(",");
        		}
        		var sum=0;
        		timer=setInterval(fn, time);
	                function fn() {
	            	   if (p1 < FSpectrum.length) {
	            		  	$('#currenttime').val(getSmpFormatDateByLong(parseInt(currenttime[p1], 10),true));
	            	   		var arr=new Array();
	            	   		var arr1=new Array();
 	            	   		for (var i=0; i < 463; i++) {
 	            				if (i < 11 || i > 451) {
 	            					arr[i]=null;
 	            					arr1[i]=null;
 	            				} else {
 	            					arr[i]=parseFloat(FSpectrum[p1][i-11]);
 	            					arr1[i]=parseFloat(FSpectrum1[p1][i-11]);
 	            				}
 	            			}
 	                    	series_FSpectrum.setData(arr);
 	                    	series_bsmodelbusy.setData(bsmodelbusy);
	            			series_bsmodelleisure.setData(bsmodelleisure);
	            			series_FSpectrum1.setData(arr1);
 	                    	series_bsmodelbusy1.setData(bsmodelbusy2);
	            			series_bsmodelleisure1.setData(bsmodelleisure2);
	            			if((!status2))
	            				p1++;
	                	} else {
	            		    begintimelong=middletime;
 	            	    	middletime=middletime+60000;
 	            	    	if(middletime>endtimelong) {
 	            	    		middletime=endtimelong;
 	            	    	}
 	            	    	if(begintimelong<endtimelong) {
 	            	    		FSpectrum=new Array();
 	            	       		FSpectrum1=new Array();
 	            	        	currenttime=new Array();
 	            	    		$.post("${pageContext.request.contextPath}/interferencequery/fslist.do",{frontId:frontId,startTime:begintimelong,endTime:middletime,isAdjust:"0",isfsreplay:"0"},
 	            	        		function(fsresult){
 	            	        		var fs=fsresult.rows1;
 	            	        		var fs1=fsresult.rows;
 	            	        		for(var i=0;i<fs.length;i++) {
 	            	        			FSpectrum[i]=new Array();
 	            	        			FSpectrum[i]=fs[i].rawMessage.split(",");
 	            	        			currenttime[i]=fs[i].timeStamp;
 	            	        			FSpectrum1[i]=new Array();
 	            	        			FSpectrum1[i]=fs1[i].rawMessage.split(",");
 	            	        			p1=0;
 	            	        			fn();
 	            	        		}},"json"); 
 	    	                
 	            	     	} 
	            		   	if(isreplay) {
	            			  	p1=0; 
	            			  	isreplay=false;
	            		   	}
	            	   	}
	                }
   				},"json");
	}
	
	/*时间转换函数  */
	Date.prototype.format = function (format) {  
        var o = {  
            "M+": this.getMonth() + 1,  
            "d+": this.getDate(),  
            "h+": this.getHours(),  
            "m+": this.getMinutes(),  
            "s+": this.getSeconds(),  
            "q+": Math.floor((this.getMonth() + 3) / 3),  
            "S": this.getMilliseconds()  
        }  
        if (/(y+)/.test(format)) {  
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));  
        }  
        for (var k in o) {  
            if (new RegExp("(" + k + ")").test(format)) {  
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));  
            }  
        }  
        return format;  
    }  
    /**   
    *转换日期对象为日期字符串   
    * @param date 日期对象   
    * @param isFull 是否为完整的日期数据,   
    *               为true时, 格式如"2000-03-05 01:05:04"   
    *               为false时, 格式如 "2000-03-05"   
    * @return 符合要求的日期字符串   
    */    
    function getSmpFormatDate(date, isFull) {  
        var pattern = "";  
        if (isFull == true || isFull == undefined) {  
            pattern = "yyyy-MM-dd hh:mm:ss S";  
        } else {  
            pattern = "yyyy-MM-dd";  
        }  
        return getFormatDate(date, pattern);  
    }  
    
    function getSmpFormatDateByLong(date, isFull) {  
        return getSmpFormatDate(new Date(date), isFull);  
    }  
    
    function getFormatDate(date, pattern) {  
        if (date == undefined) {  
            date = new Date();  
        }  
        if (pattern == undefined) {  
            pattern = "yyyy-MM-dd hh:mm:ss S";  
        }  
        return date.format(pattern);  
    }  
    
    function setupBSInfo(frontId) {
    	$.post("${pageContext.request.contextPath}/frontProcessorInfo/find.do", function(result){
    		
    		var info = '';
    		for(var i = 0; i < result.length; i++){
    			var bs_info = result[i];

    			if (bs_info.BSName == frontId) {
    				info = '本小区 ' + frontId + ':' + bs_info.BCCH + '/' + bs_info.TCH1 + '/';
    				if (bs_info.TCH2) info += (bs_info.TCH2 + '/');
    				if (bs_info.TCH3) info += (bs_info.TCH3);
    				info += '\n';
    				var fres = bs_info.fres.split(';');
    				for (var j = 0; j < fres.length; j++) {
    					info += '邻小区 ' + fres[j] + '\n';
    				}

    				 console.log(info);
    		    	$('#bs_info').html(info);
					break;
    			}
    		}
    	},"json");
    }

</script>
</body>
</html>